#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

#define FOR(i,a,n) for(int i=a,_n(n);i<_n;++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int GetMask(int t)
{
    int ans = 0;
    while(t)
    {
        int m = t%10;
        if(m==7||m==4) ans = ans * 10 + m;
        t /= 10;
    }
    t = ans;
    ans = 0;
    while(t)
    {
        int m = t%10;
        ans = ans * 10 + m;
        t /= 10;
    }
    return ans;
}

int GetAns(int a,int b)
{
    int c = a + 1;
    while(GetMask(c)!=b) ++c;
    return c;
}

int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        cout<<GetAns(a,b)<<endl;
    }
	return 0;
}
